import 'package:dio/dio.dart';
import 'package:hotfil_pub_web/service/product_data.dart';
import 'package:hotfil_pub_web/shared/http/http.dart';
// import 'package:hotfil_pub_web/shared/http_utils.dart';

class HomeData {
  int? page;
  int? perPage;
  int? total;
  num? allIncome;
  num? availableBalance;
  num? curSavePower;
  String? inviteToken;
  String? inviteTokenUser;
  String? publisherName;
  String? publisherNameEn;
  List<ProductData>? productList;

  HomeData({
    this.page = 1,
    this.perPage = 20,
    this.total = 0,
    this.allIncome = 0,
    this.availableBalance = 0,
    this.curSavePower = 0,
    this.inviteToken = '',
    this.inviteTokenUser = '',
    this.publisherName = '',
    this.publisherNameEn = '',
    this.productList,
  });

  factory HomeData.fromJson(Map<String, dynamic> json) => HomeData(
        page: json['page'] as int?,
        perPage: json['per_page'] as int?,
        total: json['total'] as int?,
        allIncome: json['allIncome'] as int?,
        availableBalance: json['availableBalance'] as int?,
        curSavePower: json['curSavePower'] as int?,
        inviteToken: json['inviteToken'] as String?,
        inviteTokenUser: json['inviteTokenUser'] as String?,
        publisherName: json['publisherName'] as String?,
        publisherNameEn: json['publisherNameEn'] as String?,
        productList: (json['productList'] as List<dynamic>?)
            ?.map((e) => ProductData.fromJson(e as Map<String, dynamic>))
            .toList(),
      );

  Map<String, dynamic> toJson() => {
        'page': page,
        'per_page': perPage,
        'total': total,
        'allIncome': allIncome,
        'availableBalance': availableBalance,
        'curSavePower': curSavePower,
        'inviteToken': inviteToken,
        'inviteTokenUser': inviteTokenUser,
        'publisherName': publisherName,
        'publisherNameEn': publisherNameEn,
        'productList': productList?.map((e) => e.toJson()).toList(),
      };
}

Future<HomeData> getHomePageData(
    {page = 1, per_page = 20, assetType = 1, showLoading = false}) async {
  var res = await Https().get('/home_page',
      params: {
        "page": page,
        "per_page": per_page,
        "assetType": assetType,
      },
      showLoading: showLoading);
  return HomeData.fromJson(res);
}
